package Test;

import entity.User;
import java.lang.reflect.Method;

public class TestTurre {
    public static void main(String[] args) throws Exception {
        Class<User> userClass = User.class;
        User user = userClass.newInstance();

        // 调用Setter方法
        Method setNameMethod = userClass.getMethod("setName", String.class);
        setNameMethod.invoke(user, "王五");
        Method setAgeMethod = userClass.getMethod("setAge", int.class);
        setAgeMethod.invoke(user, 30);

        // 调用Getter方法
        Method getNameMethod = userClass.getMethod("getName");
        String name = (String) getNameMethod.invoke(user);
        Method getAgeMethod = userClass.getMethod("getAge");
        int age = (int) getAgeMethod.invoke(user);
        System.out.println("姓名：" + name + "，年龄：" + age);

        // 调用自定义方法 showInfo()
        Method showInfoMethod = userClass.getMethod("showInfo");
        String info = (String) showInfoMethod.invoke(user);
        System.out.println("showInfo方法返回: " + info);
    }
}